<?php
namespace app\Manage\controller;

use app\common\controller\Manage;
use app\common\model\DeviceLogRepair as DeviceLogRepairModel;
use app\common\model\Payments;
use think\facade\Log;
use Request;

class DeviceLogRepair extends Manage
{
    public function index()
    {
        if(Request::isAjax()){
            $data = input('param.');
            $billAfterSalesModel = new DeviceLogRepairModel();
            return $billAfterSalesModel->tableData($data);
        }
        return $this->fetch('index');
    }

    //售后单处理
    public function audit()
    {
        $this->view->engine->layout(false);
        if(!input('?param.repair_id')){
            return error_code(13106);
        }
        $deviceLogRepairModel = new DeviceLogRepairModel();

        if(Request::isPOST()){ 
            if(!input('?param.status')){
                return error_code(10000);
            }
            $mark = input('param.mark','');
            return $deviceLogRepairModel->audit(input('param.repair_id'), input('param.status'),$mark);
        }


        $where['repair_id'] = input('param.repair_id');
        $where['status'] = $deviceLogRepairModel::STATUS_WAITAUDIT;
        $info = $deviceLogRepairModel::with('images')->where($where)->find();
        if(!$info){
            return error_code(13107);
        }

        $this->assign('info',$info);
        return [
            'status' => true,
            'data' => $this->fetch('audit'),
            'msg' => ''
        ];
    }

    //售后单查看
    public function view()
    {
        $this->view->engine->layout(false);
        if(!input('?param.repair_id')){
            return error_code(13106);
        }
        $deviceLogRepairModel = new DeviceLogRepairModel();
        $where['repair_id'] = input('param.repair_id');

        $info = $deviceLogRepairModel::with('images')->where($where)->find();
        if(!$info){
            return error_code(13107);
        }

        $this->assign('info',$info);
        return [
            'status' => true,
            'data' => $this->fetch('view'),
            'msg' => ''
        ];
    }

}
